package com.example.administrator.kaohedemo.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.kaohedemo.Action.Actions;
import com.example.administrator.kaohedemo.Action.TaskAction;
import com.example.administrator.kaohedemo.Interface.AdapterListener;
import com.example.administrator.kaohedemo.R;

import java.util.List;

/**
 * Created by Administrator on 2016/6/21.
 */
public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.TaskViewHolder> {

    private final TaskAction taskAction;
    private Context context;
    private List<String> list;

    public TaskAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        taskAction = TaskAction.getInstense();
    }

    @Override
    public TaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_task, parent, false);
        return new TaskViewHolder(view);
    }

    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }

    @Override
    public void onBindViewHolder(TaskViewHolder holder, int position) {
        holder.class_type.setText(list.get(position));
        if (position == 0) {
            holder.class_type.setTextColor(Color.parseColor("#808080"));
        } else {
            holder.class_type.setTextColor(Color.parseColor("#DCDCDC"));
        }
    }

    class TaskViewHolder extends RecyclerView.ViewHolder {
        LinearLayout item;
        TextView class_type;

        public TaskViewHolder(final View itemView) {
            super(itemView);
            class_type = (TextView) itemView.findViewById(R.id.class_type);
            item = (LinearLayout) itemView.findViewById(R.id.item);
            item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    taskAction.SendItemClick(Actions.TaskActions.TYPE_ITEM_ONCLICK, getLayoutPosition());
                }
            });
            item.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    taskAction.SendItemClick(Actions.TaskActions.TYPE_ITEM_ONLONGCLICK, getLayoutPosition());
                    return true;
                }
            });
        }
    }
}
